﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections.Generic;
using COM.OA.Entity;
using COM.OA.BLL;

public partial class qs_wenjian_chuansongwenjian : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btBumenQF_Click(object sender, EventArgs e)
    {

        users loginuser = Session["loginuser"] as users;
        if (loginuser == null)
        {
            this.Response.Write(string.Format(GetRedirect.REDIRECT, "../login.aspx"));
        }
        else
        {
            int userId = loginuser.u_id;

        string bumen = this.DropDownList1.Text;
        SqlParameter parambumen = new SqlParameter("@deptid", bumen);
        IList<liandongrenqs> lists = BLLGeneric.Select<liandongrenqs>(CommandType.StoredProcedure, "liandongqs", parambumen);
        //取要传的文件
        //if (this.fluWenJian.FileName.Equals(""))
        //{
        //    this.Response.Write(string.Format(GetRedirect.WINALERT, "请选择要发送的文件"));

        //}
        //else { 
        string name = this.fluWenJian.FileName;

        int startIndex = this.fluWenJian.FileName.LastIndexOf(@"\") + 1;
        string fileName = this.fluWenJian.FileName.Substring(startIndex);
        string phyFileName = this.Server.MapPath(@"..\qs_wenjian\" + "upload") + @"\" + fileName;
        this.fluWenJian.SaveAs(phyFileName);




        //取当前时间
        DateTime fsendtiem = DateTime.Now;
        //取当前登陆人名
        
            //string fasongren = "haha";
            //string where1 = "u_username='{0}'";
            //where1 = string.Format(where1, fasongren);
            //IList<users> listuname = usersBLL.Select(where1);
            //users user = listuname[0];
            //int userId = user.u_id;


            //取部门ID

            int bumenid = Int32.Parse(bumen);

            //往消息实体类里存值
            files fs = new files();

            fs.f_filename = name;
            //所有默认归纳为其他类别
            fs.f_ftype_id = 1;
            fs.f_dept_id = bumenid;
            //发送人id
            fs.f_sendu_id = userId;
            //接收人id

            //是否共享 0为否1为是
            fs.f_isshare = 0;
            //备注
            //fs.f_remark = "";
            //是否回执0为否1为是
            fs.f_isreturn = 0;
            //读否
            fs.f_isread = 0;
            //阅读次数
            fs.f_readdegree = 0;
            //阅读时间
            fs.f_releasetime = DateTime.Parse("2008-01-01");
            //状态 
            fs.f_state = 0;




            //循环取接收人
            if (lists.Count > 0)
            {
                foreach (liandongrenqs jdrqs in lists)
                {
                    int jieshourenid = jdrqs.U_id;
                    fs.f_takeu_id = jieshourenid;
                    //往数据库里插入数据
                    filesBLL.Insert(fs);
                }


                this.Response.Write(string.Format(GetRedirect.WINALERT, "插入成功"));
           
            }

        }


    }

}
